package com.originalpoint.origin_server.service.Impl;

import com.originalpoint.origin_server.annotations.UserAnnotation;
import com.originalpoint.origin_server.mapper.UserMapper;
import com.originalpoint.origin_server.pojo.*;
import com.originalpoint.origin_server.service.UserService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.PipedReader;
import java.util.List;

/**
 *业务层，在这里实现业务的aop增强
 */
@Service
//@Data
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

//    Double price = null;
//    Integer quantityOrdered = null;

    //反查地址id
    @Override
    public Integer getAddr(Address address) {
        return userMapper.getAddr(address);
    }
//    @Override
//    //获取菜品单价
//    public Double getSinglePrice(Integer dishId) {
//        return userMapper.getSinglePrice(dishId);
//    }
//
//    @Override
//    //获取菜品剩余数目
//    public Integer getQuantity(Integer dishId) {
//        return userMapper.getQuantity(dishId);
//    }

    @Override
    //获取菜品信息
    public Dish getDishInfo(Integer dishId) {
        return userMapper.getDishInfo(dishId);
    }

    @Override
    //order_dish三字段插入
    public void insertThree(OrderDish orderDish) {
        userMapper.insertThree(orderDish);
    }

    @Override
//    @UserAnnotation//完成增强，传入totalPrice
    public void insertOrders(Orders orders) {
        userMapper.insertOrders(orders);
    }

    @Override
    //菜品数量更新
    public void updateQuantityLeft(Integer quantity,Integer dishId) {
        userMapper.updateQuantityLeft(quantity,dishId);
    }

    @Override
    //特定订单查询
    public Integer queryOrderId(String time) {
        return userMapper.queryOrderId(time);
    }

    @Override
    //order_dish表orderID设置
    public void setodOrderID(Integer id, String time) {
        userMapper.setodOrderID(id,time);
    }

    @Override
//    查询订单数据
    public List<Orders> queryOrders(Integer userId) {
        return userMapper.queryOrders(userId);
    }

    @Override
//    查询用户信息
    public User queryUserInfo(Integer userId) {
        return userMapper.queryUserInfo(userId);
    }

    @Override
//    插入地址信息
    public void setAddr(Address address) {
        userMapper.setAddr(address);
    }

    @Override
    //插入用户的地址关联
    public void insertAddr(Integer u_addressId,Integer userId) {
        userMapper.insertAddr(u_addressId,userId);
    }

    @Override
    //修改用户信息
    public void updateUserInfo(User user) {
        userMapper.updateUserInfo(user);
    }

//列表渲染
    @Override
    //商家信息查询
    public List<Merchat> getAllMerchats() {
        return userMapper.getAllMerchats();
    }
    @Override
    //商家菜品查询
    public List<Dish> getAllDishes(Integer id) {
        return userMapper.getAllDishes(id);
    }
}
